package auth

import (
	"time"

	"gorm.io/gorm"
)

// User 用户模型
type User struct {
	ID        uint           `json:"id" gorm:"primaryKey;autoIncrement" comment:"用户ID"`
	Username  string         `json:"username" gorm:"size:50;unique;not null" binding:"required" comment:"用户名"`
	Nickname  string         `json:"nickname" gorm:"size:50" comment:"昵称"`
	Email     string         `json:"email" gorm:"size:100" comment:"邮箱"`
	Phone     string         `json:"phone" gorm:"size:20" comment:"手机号"`
	Password  string         `json:"-" gorm:"size:255;not null" comment:"密码"`
	Avatar    string         `json:"avatar" gorm:"size:255" comment:"头像"`
	Status    int            `json:"status" gorm:"default:1;not null" comment:"状态(1:启用 0:禁用)"`
	LastLogin *time.Time     `json:"last_login" comment:"最后登录时间"`
	CreatedAt time.Time      `json:"created_at" gorm:"autoCreateTime" comment:"创建时间"`
	UpdatedAt time.Time      `json:"updated_at" gorm:"autoUpdateTime" comment:"更新时间"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index" comment:"删除时间"`
}

// TableName 设置表名
func (User) TableName() string {
	return "users"
}

// LoginRequest 登录请求
type LoginRequest struct {
	Username string `json:"username" binding:"required" comment:"用户名"`
	Password string `json:"password" binding:"required" comment:"密码"`
}

// LoginResponse 登录响应
type LoginResponse struct {
	Token     string    `json:"token" comment:"访问令牌"`
	ExpiresAt time.Time `json:"expires_at" comment:"过期时间"`
	User      UserInfo  `json:"user" comment:"用户信息"`
}

// UserInfo 用户信息
type UserInfo struct {
	ID       uint   `json:"id" comment:"用户ID"`
	Username string `json:"username" comment:"用户名"`
	Nickname string `json:"nickname" comment:"昵称"`
	Email    string `json:"email" comment:"邮箱"`
	Phone    string `json:"phone" comment:"手机号"`
	Avatar   string `json:"avatar" comment:"头像"`
	Status   int    `json:"status" comment:"状态"`
}

// ChangePasswordRequest 修改密码请求
type ChangePasswordRequest struct {
	OldPassword string `json:"old_password" binding:"required" comment:"原密码"`
	NewPassword string `json:"new_password" binding:"required,min=6" comment:"新密码"`
}

// UpdateProfileRequest 更新个人信息请求
type UpdateProfileRequest struct {
	Nickname *string `json:"nickname" comment:"昵称"`
	Email    *string `json:"email" binding:"" comment:"邮箱"`
	Phone    *string `json:"phone" comment:"手机号"`
	Avatar   *string `json:"avatar" comment:"头像"`
}

// MenuInfo 菜单信息
type MenuInfo struct {
	ID       uint        `json:"id" gorm:"column:id" comment:"菜单ID"`
	Name     string      `json:"name" gorm:"column:name" comment:"菜单名称"`
	Title    string      `json:"title" gorm:"column:title" comment:"菜单标题"`
	Path     string      `json:"path" gorm:"column:path" comment:"菜单路径"`
	Icon     string      `json:"icon" gorm:"column:icon" comment:"菜单图标"`
	Sort     int         `json:"sort" gorm:"column:sort" comment:"排序"`
	ParentID *uint       `json:"parent_id" gorm:"column:parent_id" comment:"父级ID"`
	Children []*MenuInfo `json:"children,omitempty" gorm:"-" comment:"子菜单"`
}
